home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bfile2.zip / BFILE.H < prev    next >
Text File  |  1991-12-30  |  6KB  |  165 lines

  1. /*
  2.  
  3.       bfile.h
  4.       Btrieve class for Borland C++
  5.       09/06/91
  6.  
  7.       Douglas J. Reilly
  8.       Access Microsystems Inc.
  9.       404 Midstreams Road
  10.       Brick, New Jersey  08724
  11.       (908) 892-2683
  12.       CompuServe 74040,607
  13.  
  14.       Comments?  Questions?  Suggestions?
  15.       Have a paying C/C++ programming job you need done?
  16.       Give me a call.
  17.  
  18.       Released into the public domain.  Do with it as you see fit, but
  19.       if you do anything really neat with it, let me know...
  20.  
  21. 10/15/91  DR  Make len default to 0 in constructor, and then set it from
  22.                  open return.
  23.               Set newmode in open() call to -99 by default, ensures
  24.                  that we realize that no mode was sent.
  25. 11/11/91  DR  Multiple fixes and changes to better handle variable length
  26.                  records.
  27.               Add clone_file() to public interface.
  28. 11/12/91  DR  Add support for just_update parm to put_rec();
  29. */
  30.  
  31. #ifndef BFILE_H
  32. #define BFILE_H
  33. #include "btrieve.h"
  34. extern "C" {
  35. int BTRV(int ,char *,char *,int *,char *,int );
  36. }
  37.  
  38. class bfile {
  39.    char pos_blk[128];        // position block
  40.    char fname[64];           // physical file name
  41.    char logical_name[10];    // logical file name (not used yet)
  42.    int  mode;                // open mode
  43.    int  file_flag;           // flag from STAT call.
  44.    int  fixed_len;           // The non-variable length.
  45.    int  rec_len;             // record length, i.e. higher than above for
  46.                              //    variable lenght records.
  47.                              //    This is == to above UNLESS you pass
  48.                              //    a length to constructor.  For variable
  49.                              //    length records, you MUST pass a length
  50.                              //    that is the upper limit you expect.
  51.    int  last_rec_len;        // most recent returned len
  52.    int  key_num;             // current key number
  53.    int  num_keys;            // number of keys in file
  54.    int  status;              // error status
  55.    int  opened;              // opened flag, not really essential because data
  56.                              //   seemed like it was as natural a flag
  57.                              //   as possible, since we don't want to write
  58.                              //   data to null.
  59.    char *data;               // The data, of course...
  60.    char owner[60];           // owner of the file, used for secured files.
  61. public:
  62.   // file name, lenght, owner, and open mode
  63.   // Note that constructor opens file, destructor closes.
  64.    bfile(char *name,int len=0,char *towner=0,int newmode=0);
  65.    ~bfile();
  66.   // Close file, free up data pointer above.
  67.    int  close();
  68.   // Open, really SB reopen I guess since only useful after close...
  69.    int  open(int newmode=-99);
  70.   // file name, lenght, owner, and open mode
  71.   // Note that this opens file, destructor closes.
  72.    newfile(char *name,int len=0,char *towner=0,int newmode=0);
  73.   // Gets a record.  Uses key 0 unless you set key number (below).
  74.    int  get_rec(char *keystr,int op=B_GET_EQ);
  75.   // Self explanatory...
  76.    void set_key_num(int key=0)
  77.         {
  78.           // sanity check...
  79.            if ( key<num_keys )
  80.            {
  81.               key_num=key;
  82.            }
  83.         }
  84.    int  get_key_num() { return key_num; }
  85.    int  get_key_len(int key_num=-1);
  86.   // Get the number of keys allowed.
  87.    int  get_num_keys() { return num_keys; }
  88.   // take newdata and copy it into the data element.
  89.    int  set_data(char *newdata)
  90.         {
  91.            if ( data!=NULL )
  92.            {
  93.               memcpy(data,newdata,rec_len);
  94.               return(1);
  95.            }
  96.            return(0);
  97.         }
  98.   // return pointer to data.
  99.    char *get_data(int *last_len=0)
  100.         {
  101.            if ( last_len!=0 )
  102.            {
  103.               *last_len=last_rec_len;
  104.            }
  105.            return data;
  106.         }
  107.   // return pointer to COPY data.
  108.    char *dup_data()
  109.         {
  110.            char *datacopy=0;
  111.            if ( opened && data!=0 )
  112.            {
  113.               datacopy=new char[rec_len];
  114.               if ( datacopy!=0 )
  115.               {
  116.                  memset(datacopy,EOS,rec_len);
  117.                  memcpy(datacopy,data,rec_len);
  118.               }
  119.            }
  120.            return datacopy;
  121.         }
  122.   // Insert or update record.  could make seperate functions to force one
  123.   //   or the other.  I prefer this.
  124.   //   SEE BELOW...
  125.    int  put_rec(char *keystr=0,int tlen=0,int just_update=0);
  126.   // Insert.  made seperate functions to force insert.
  127.    int  insert(char *keystr=0,int tlen=0);
  128.   // self explanatory...except that if keystr==0, positioning is not done
  129.    int  del_rec(char *keystr=0);
  130.   // allow user to get status after operation.
  131.    int  get_status(){ return status; }
  132.   // gets a full FIL_SPEC record (see btrieve.h)
  133.    void get_bstat(struct FIL_SPEC *);
  134.   // returns rec_len private element.
  135.    int  get_len() { return rec_len; }
  136.   // returns fixed_len private element.
  137.    int  get_fixed_len() { return fixed_len; }
  138.   // returns last_rec_len private element.
  139.    int  get_last_len() { return last_rec_len; }
  140.    int  get_pos(char *buf)
  141.    {
  142.       int tlen=4;
  143.       char temp[256];
  144.       status=BTRV(B_GET_POS,pos_blk,buf,&tlen,temp,key_num);
  145.       return(status);
  146.    }
  147.    int set_pos(char *buf,char *keystr=0);
  148.    int get_fname(char *tstr)
  149.    {
  150.       if ( tstr!=0 )
  151.       {
  152.          strcpy(tstr,fname);
  153.       }
  154.       return(tstr!=0);
  155.    }
  156.    int clone_file(char *destfname,int overwrite=1);
  157.    int variable_len() { return (file_flag&1); }
  158.    int key_only() { return (file_flag&16); }
  159.    int key_from_data(char *);
  160.    long num_links(int tkey);
  161.    int get_pos_blk(char *t) { memcpy(t,pos_blk,128); return(data!=0); }
  162.    int set_pos_blk(char *t) { memcpy(pos_blk,t,128); return(data!=0); }
  163. };
  164. #endif
  165.